/*
 * @Author: C.
 * @Date: 2021-08-31 17:10:49
 * @LastEditTime: 2021-09-06 09:47:36
 * @Description: file content
 */
import { PosInfo, FieldInfo, EleStyle } from '../types';
import { fontLayout } from '../maps';
import { usePrintStore } from '/@/store/modules/print';
// import { reactive, watch } from 'vue';
export function usePrintStyle(target: FieldInfo, options?: any) {
  const printStore = usePrintStore();
  function setPos(info: Pick<PosInfo, 'x' | 'y'>) {
    Object.assign(target.style, info);
    // console.log(target.style, 222);
  }
  function setSize(info: PosInfo) {
    Object.assign(target.style, info);
    // console.log(target.style, 222);
  }

  // function setFieldToggle() {
  //   printStore.setToggle(['1']);
  // }
  function setActivated() {
    printStore.setCurrentNode(target);
    printStore.setToggle(['field', options?.blockName ?? '']);
  }
  return [setPos, setSize, setStyle, setActivated];
}

/**
 * @description:  处理样式信息
 * @param {*} e 元素的位置和样式信息
 * @param {*} type 处理方式
 * @return {*}
 */
function setStyle(e: EleStyle, type = '') {
  // console.log(e);
  const typeCheck = type == 'only-style';
  const result = {};
  Object.keys(e).forEach((item) => {
    const currentVlaue = e[item];
    switch (item) {
      case 'x':
        if (typeCheck) break;
        result['left'] = currentVlaue + 'px';
        break;
      case 'y':
        if (typeCheck) break;
        result['top'] = currentVlaue + 'px';
        break;
      case 'w':
        if (typeCheck) break;
        result['width'] = currentVlaue + 'px';
        break;
      case 'h':
        if (typeCheck) break;
        result['height'] = currentVlaue + 'px';
        break;
      case 'fontSize':
        result['fontSize'] = currentVlaue + 'px';
        break;
      case 'fontWeight':
        result['fontWeight'] = currentVlaue;
        break;
      case 'fontFamily':
        result['fontFamily'] = currentVlaue;
        break;
      case 'textAlign':
        result['justifyContent'] = fontLayout[currentVlaue];
        break;
      default:
        break;
    }
  });
  return result;
}
